package com.ntv.persistent.flashnews.impl;

import java.util.HashMap;
import java.util.List;

import org.springframework.dao.DataAccessException;

import com.ntv.domain.INews;
import com.ntv.persistent.AbstractDao;
import com.ntv.persistent.PersistentException;
import com.ntv.persistent.flashnews.IFlashNewsDao;

public class FlashNewsDao extends AbstractDao implements IFlashNewsDao {

	interface CONST {
		interface QUERY {
			String CURRENT_DAY_FLASHNEWS = "select 	news_id, "+ 
				"head_line,"+ 
				"description, "+
				"date, "+
				"location,"+ 
				"created_by,"+ 
				"date_of_creation,"+ 
				"updated_by, "+
				"date_of_update "+	 
				" from "+
				"flash_news where DATE_FORMAT(date,'%Y%m%d') = DATE_FORMAT(now(),'%Y%m%d')"+ 
				"limit 0, 10";			
		}
	}
	
	public List<INews> getCurrentDayFlashNews() throws PersistentException 
	{
		try 
		{
			List<INews> newsList = getNamedParameterJdbcTemplate().query(CONST.QUERY.CURRENT_DAY_FLASHNEWS, new HashMap(), getRowMapper());
			return newsList;
		}
		catch(DataAccessException ex)
		{
			throw new PersistentException(ex);
		}
	}
  }
